//
//  CharRecord.m
//  SimulacraDB
//
//  Created by Andre Cohen on 8/9/08.
//  Copyright 2008 __MyCompanyName__. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "CharRecord.h"
#import "ByteArray.h"

@implementation CharRecord

@synthesize value;

- (id)initWithData:(ByteArray *)data {
	[self init];
	[self setValue:[data toString]];
	return self;
}

- (id)initWithValue:(NSObject *)object {
	[self init];
	[self setValue:(NSString *)object];
	return self;
}

- (void)setValueFromData:(ByteArray *)data {
	[self setValue:[data toString]];
}

- (void)setValue:(NSObject *)data {
	if(![[data class] isSubclassOfClass:[NSString class]])
		return;
	value = [NSMutableString stringWithString:(NSString *)data];
}

- (ByteArray *)toByteArray {
	return [ByteArray createFromString:value];
}

- (int) hash {
	return 0;
}

- (int) size {
	return [value length];
}

- (NSString *)description {
	return value;
}

- (BOOL)lessThan:(id)anObject {
	if(![[anObject class] isSubclassOfClass:[CharRecord class]]){
		NSLog(@"Error comparing different types of RecordData");
		return NO;
	}
	return [value compare:[(CharRecord *)anObject value] options:NSCaseInsensitiveSearch]==NSOrderedAscending;
}

- (BOOL)greaterThan:(id)anObject {
	if(![[anObject class] isSubclassOfClass:[CharRecord class]]){
		NSLog(@"Error comparing different types of RecordData");
		return NO;
	}
	return [value compare:[(CharRecord *)anObject value] options:NSCaseInsensitiveSearch]==NSOrderedDescending;
}

- (BOOL)equalTo:(id)anObject {
	if(![[anObject class] isSubclassOfClass:[CharRecord class]]){
		NSLog(@"Error comparing different types of RecordData");
		return NO;
	}
	return [value compare:[(CharRecord *)anObject value] options:NSCaseInsensitiveSearch]==NSOrderedSame;
}

@end
